﻿;_____________________________________________________________________
;---------------------------------------------------------------------
;	File: PML_GUI_actions
;---------------------------------------------------------------------
;	Group: Overview
;
;		Handles user interaction with the PM App Launcher GUI.
;
;	Group: About
;		General script file information
;
;		- *Written By:* 	Rameen Bakhtiary
;		- *Last Modified:*	11/30/2011
;_____________________________________________________________________
;---------------------------------------------------------------------




;=================================================================
;		USER CLICKED IN ICON AREA -- Determine if an icon was
;		clicked, and which one.
;=================================================================
PMgui_appIcons:
	MouseGetPos,mx,my
	
	
	;_________________
	; 	CWI SEARCH BAR
	;
		If (mx>34 && mx<81 && my>135 && my<160)
			Goto, cwi_search_bar
	
	
	;_____________
	;	MFRs Spec
	
	If (mx>112 && mx<158 && my>138&& my<160)
		Goto, new_mfr_spec
	
	
	;_____________
	;	 Threads
	;
	If (mx>186 && mx<233 && my>138 && my<160)
		Goto, threads
	
	
	;______________
	; 	Spec Finder
	;
	If (mx>47 && mx<116 && my>190 && my<220)
		Goto, specfinder
	
	
	;_____________
	;	  Mandrels
	;
	If (mx>152 && mx<221 && my>190 && my<220)
		Goto, mandrels
	
	
	;_____________
	;		Titler
	;
	If (mx>34 && mx<87 && my>255 && my<285)
		Goto, cwi_title_creator
	
	
	;____________________
	;	 PTI Checkvalves
	;
	If(mx>100 && mx<160 && my>258 && my<285)
		Goto, ptiCVs
	
	
	;_____________
	; 		Clamps
	;
	If(mx>183 && mx<233 && my>260 && my<285)
		Goto, EZclamps
Return




;=================================================================
;                     BUTTON  ICON  ACTIONS
;=================================================================
	
	;_____________
	;	specFinder
	;
	specFinder:
		gui, 1:destroy
		If (WinExist("Material Specs")){
			WinActivate, Material Specs
			return
		}	
		If ! FileExist("Include\Spec Finder\specFinder.exe"){  ;Missing specFinder
			error_handle("missing", "Spec Finder")
			return
		}
		IfWinExist, Permanent Monitoring Apps
			gui, 1:destroy
		run, Include\Spec Finder\specFinder.exe
		WinWait, Material Specs
	return


	;__________
	;	ptiCVs
	;
	ptiCVs:
		gui, destroy
		run, %PTIFILE%
	return


	;____________
	;	EZclamps
	;
	EZclamps:
		gui, destroy
		run, %CLAMPFILE%
	return


	;_______________
	;	New_MFR_Spec
	;
	New_MFR_Spec:
		gui, destroy
		run, %MFRSpecFILE%
	return


	;____________
	;	Mandrels
	;
	Mandrels:
		gui, 1:destroy
		run, %MandrelsFILE%
	return


	;_____________________
	;	CWI_Title_Creator
	;
	CWI_Title_Creator:
		gui, destroy
		If ! fileExist("Include\Titler\CWI Title Creator.exe"){
			error_handle("missing", "CWI Title Creator.exe")
			return
		}
		run, Include\Titler\CWI Title Creator.exe
	return
	

	;___________
	;	Threads
	;
	threads:
		gui, destroy
		if ! fileexist("Include\Threads\threads.exe"){
			error_handle("missing", "Connection Data (Threads.exe)")
			return
		}
		run, Include\Threads\threads.exe
	return
	

	;__________________
	;	CWI_Search_Bar
	;
	CWI_Search_Bar:
		gui, destroy
		if ! fileexist("Include\CWI SB\CWI Search Bar.exe"){ 
			;-- CWI Search Bar.exe not found --
			error_handle("missing", "CWI Search Bar.exe")
			return
		}
		run, Include\CWI SB\CWI Search Bar.exe
	return


	;____________________
	; 	ABOUT/HELP BUTTON
	;
	AboutME:
	helpMe:
		Run, %HELP_FILE%
		;~ FileRead, aboutTxt, Resource\PML_about.txt
		;~ SplashImage, , FM11 WM550 m2 CX0 W700, , %aboutTxt%, About PM Application Launcher, Courier New
	Return


;===================================================
;		EXIT THE PROGRAM FROM TRAY
;===================================================
	CloseHer:
		ExitApp
	return





;=================================================================
;                          TITLE IMAGE ACTION
;=================================================================
titleAction:


	;===================================================
	;			DOUBLE-CLICK THE TITLEBAR
	;===================================================
	If (A_GuiEvent="doubleclick"){
		Gui, Destroy
		
		;________________________________________
		; 		GET TITLE ACTION SETTING FROM REG
		;
		RegRead, dClickTitleAction, HKCU, Software\PM App Launcher\Defaults, titleAction
		If ErrorLevel
			dClickTitleAction = pubfold
		
		Run, % getTitleAction(dClickTitleAction)		
		Return
	}
	
	
	
	;===================================================
	;			CLICK ON THE TITLE BAR
	;===================================================
	If (A_GuiEvent="Normal"){	;Left-clicked title-bar
		CoordMode, Mouse, Relative
		MouseGetPos, mx, my
		If (mx>247 && mx<265 && my>6 && my<20)	;-- Close button
			Goto, GuiClose
		If (mx>224 && mx<244 && my>6 && my<20)	;-- Help button
			Goto, helpMe
		Else
			PostMessage, 0xA1, 2,,, A		;Hold down to drag GUI
	}
Return



				



;=================================================================
;                 RIGHT-CLICK  ACTION  (CONTEXT MENU)
;=================================================================
GuiContextMenu:	
	MouseGetPos,,,,cont
	
	;_________________________________
	; 		RIGHT-CLICKED ON TITLE-BAR
	;
	if cont = Static1
		Menu, title, Show
	
return




;_____________________________________ TITLE MENU ACTIONS __________________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
		



;=================================================================
;                    LAUNCH PM APP LAUNCHER WEBSITE
;=================================================================
LaunchWebsite:
	gui, Destroy
	run, %webSite_URL%
return
		
		
		
		
;=================================================================
;               BROWSE ENGINEERING PUBLIC FILES/FOLDERS
;=================================================================
browsePublic:
	gui, Destroy
	
	StringReplace, item, A_ThisMenuItem, Browse%a_space%,,
	StringReplace, item, item, Open%a_space%,,
	item := Trim(item)
	
	
	if item=userlist
		run, %ulist%
	
	else if item=versioncheck
		run, %version_INI%
	
	else if item=engineering public
		run, explore %epub%
	
	else if item=public pm app Launcher folder
		run, explore %pmPub%
		
	else
		run, %epub%
	
return




;=================================================================
;                       SET DEFAULT TITLE ACTION
;=================================================================
setTitleAction:


	RegRead, dClickTitleAction, HKCU, Software\PM App Launcher\Defaults, titleAction	
	
	If ErrorLevel
	{
		pubFold=1
		dClickTitleAction = pubFold
	} 
	else
		%dClickTitleAction% := 1
	
	tempTitleSetting := dClickTitleAction		
	
	Gui, 10:+AlwaysOnTop
	Gui, 10:Add, Radio, x42 y40 w190 h30 vpubfold gtitleSet, Browse Engineering Public
	Gui, 10:Add, Radio, x42 y70 w240 h30 vpubpmlfold gtitleSet, Browse Public PM App Launcher Folder
	Gui, 10:Add, Radio, x42 y100 w190 h30 vulist gtitleSet, Open userList
	Gui, 10:Add, Radio, x42 y130 w190 h30 vvercheck gtitleSet, Open versionCheck
	Gui, 10:Add, Radio, x42 y160 w220 h30 vwebsite gtitleSet, Launch PM App Launcher Website
	Gui, 10:Add, Button, x82 y200 w90 h30 gsubmitTitleAction, Submit
	Gui, Font, S11 CBlue, Arial
	Gui, 10:Add, Text, x2 y10 w290 h30 +Center, Choose default double-click action
	Gui, 10:Show, w294 h248, Set Title Action	
	
	Sleep 50
	buttonNumber := buttonNumGet(dClickTitleAction)
	control, check,, Button%buttonNumber%, Set Title Action
return


;=================================================================
;                GET BUTTON NUMBER FROM BUTTON VARIABLE
;=================================================================
buttonNumGet(a){
	
	if a = pubFold
		bNumber = 1
	
	else if a = pubpmlfold
		bNumber = 2
	
	else if a = ulist
		bNumber = 3
		
	else if a = vercheck
		bNumber = 4
	
	else if a = Website
		bNumber = 5
	
	else ;just in case
		bNumber = 1
	
	return bNumber
}


;==============================
;	CLOSE/EXIT SETTINGS GUI
;==============================
10guiescape:
10GuiClose:
	gui, 10:destroy
return




;=================================================================
;		TITLE ACTION GUI - SELECTION CHANGE ROUTINE
;=================================================================
titleSet:
	;Set tempTitleSetting to the name of the button's variable
	;since that is what's saved in the user's reg.
	tempTitleSetting := A_GuiControl
return





;=================================================================
;		TITLE ACTION GUI - SUBMIT SETTINGS BUTTON
;=================================================================
submitTitleAction:
	gui, submit
	gui, Destroy

	RegWrite, REG_SZ, HKCU, Software\PM App Launcher\Defaults, titleAction, %tempTitleSetting%	
return






;=================================================================
;             GET THE TITLE ACTION FROM THE REGISTRY VALUE
;=================================================================
getTitleAction(A){
	
	global
	
	if a = pubFold
		Action = explore %epub%
	
	else if a = pubpmlfold
		Action = explore %pmPub%
	
	else if a = vercheck
		Action = %version_INI%
	
	else if a = Website
		Action = %webSite_URL%
	
	else if a = ulist
		Action = %uList%
	
	else ;just in case
		Action = explore %epub%
	
	return Action
}












		
		
		
		